﻿namespace Mp3Observer.Common.Controls
{
    #region usings

    using System.Windows.Forms;
    //using Microsoft.WindowsAPICodePack.Dialogs;
    //using Microsoft.WindowsAPICodePack.Shell;
    //using MS.WindowsAPICodePack.Internal; 

    #endregion

    /// <summary>
    /// Class that is used to show special dialogs, different dialog types depending on operating system (winxp,vista,w7)
    /// </summary>
    public class Dialogs
    {
        /// <summary>
        /// Shows the ShowFolderDialog.
        /// </summary>
        /// <param name="initialDirectory">The initial directory.</param>
        /// <returns>null or the selected directory.</returns>
        public string ShowFolderDialog(string initialDirectory)
        {
            // Windows XP
            var folderBD = new FolderBrowserDialog();
            folderBD.SelectedPath = initialDirectory;
            DialogResult result = folderBD.ShowDialog();
            if (result != DialogResult.OK)
                return null;
            else
                return folderBD.SelectedPath;
            /*
            if (CoreHelpers.RunningOnVista)
            {
                var cfd = new CommonOpenFileDialog();
                cfd.EnsureReadOnly = true;
                cfd.IsFolderPicker = true;
                cfd.InitialDirectory = initialDirectory;
                cfd.AllowNonFileSystemItems = true;

                if (cfd.ShowDialog() == CommonFileDialogResult.OK)
                {
                    var folder = cfd.FileAsShellObject as ShellFolder;
                    if (folder != null)
                        return folder.ParsingName;

                    var library = cfd.FileAsShellObject as ShellLibrary;
                    if (library != null)
                        return library.DefaultSaveFolder;
                }
                else
                    return null;
            }
            else
            {
                // Windows XP
                var folderBD = new FolderBrowserDialog();
                folderBD.SelectedPath = initialDirectory;
                DialogResult result = folderBD.ShowDialog();
                if (result != DialogResult.OK)
                    return null;
                else
                    return folderBD.SelectedPath;
            }
            return null;*/
        }
    }
}
